Sprite Byte: Making Sprite Graphics Persist

Level: any

by Alyce Watson [http://alycesrestaurant.com/]

Home

Wire 1.0

Gif Viewer

Report Generation

Flow Charting

Stylebits Corner

Tip Corner

API Corner

CodeAChrome

Sprite Byte

Control Panel Applets

HTTPS Data

Eddie

Submissions

Index

Sprite Bytes are small tutorials that address a single method to be used with sprites in Liberty BASIC.

You can't use FLUSH!

The graphics flush command causes graphics to persist. If a window is obscured by another window, or if it is minimized, then restored, the graphics disappear. To keep the graphics visible at all times with regular graphics commands, we issue the flush command. You cannot simply use FLUSH with sprite graphics! Sprite graphics work in an entirely different way than regular Liberty BASIC graphics. Sprite commands are documented in a separate section of the helpfile. For best results, do not attempt to combine regular graphics commands with sprite commands. Sprites are meant to show continuous animations. They are mainly intended for games.

You can make sprite graphics stick!

There are three ways to make sprite graphics persist, so that the window doesn't display a blank graphics area after it has been obscured, or minimized and restored. The first way is documented in the helpfile topic called "Flushing Sprite Graphics." It requires you to use GETBMP to capture the image on the window, then DRAWBMP and FLUSH to flush the image.

print #w.g, "getbmp KeepIt 0 0 300 200";

print #w.g, "drawbmp KeepIt 0 0; flush";

This method is not recommended. Each flush consumes memory. If you do use the method, be sure to issue a delsegment command to delete each previously flushed segment of graphics memory, or the program will soon crash with an "out of memory" error.

There is a better way to ensure that sprite graphics don't disappear when a window is obscured. Instead of attempting to flush the graphics, draw the sprites on a timer, using the drawsprites command. Each time the command is issued, the sprite graphics are updated on the screen. Your program will never be without sprite graphics for more than a fraction of a second.

timer 500, [updateScreen]
'other code
[updateScreen]
#window.graphicbox "drawsprites"
wait

This third way also works, but it takes some care. You can issue the drawsprites command over and over in a continuous loop. Be sure to issue a SCAN command, and a Sleep API call if you use this method. SCAN allows the program to process events like button and menu clicks, and Sleep stops your program from using 100% of the processor cycles.

[loop]
SCAN
#window.graphicbox "drawsprites"
'other program code goes here
calldll #kernel32, "Sleep",10 as long, ret as void
goto [loop]


Home

Wire 1.0

Gif Viewer

Report Generation

Flow Charting

Stylebits Corner

Tip Corner

API Corner

CodeAChrome

Sprite Byte

Control Panel Applets

HTTPS Data

Eddie

Submissions

Index